package com.ea.eadp.nexus.test.pageDefinition;

import com.ea.eadp.nexus.test.common.PageOperation;
import com.ea.eadp.nexus.test.common.SystemProperties;
import com.ea.eadp.nexus.test.common.TestUtil;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.support.ui.ExpectedCondition;
import org.openqa.selenium.support.ui.WebDriverWait;

public class Signin_Mobile extends BasePage {
    public static final String uri = baseUri + TestUtil.SigninMobileConnectURI();
    public static final String redirectURI = SystemProperties.instance().getProperty(SystemProperties.RedirectUri);

    public Signin_Mobile(WebDriver driver) {
        super(driver, Signin_Mobile.class);
    }

    public void navigate() {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(uri);
        driver.get(uri);
    }

    public void navigate(String uri) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(uri);
        driver.get(uri);
    }

    public void setSigninEmail(String email) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(email);
        PageOperation.SendKeyToElement(driver, "email", email);
    }

    public void setSigninPassword(String password) {
        driver.switchTo().window(this.operationWindowHandle);
        log.info(password);
        PageOperation.SendKeyToElement(driver, "password", password);
    }

    public void clickToSigninComplete() throws Exception {
        clickToSigninComplete(true);
    }

    public void clickToSigninComplete(boolean verification) throws Exception {
        driver.switchTo().window(this.operationWindowHandle);
        driver.findElement(By.className("fut-btn")).click();
        if(verification == true) {
            Thread.sleep(5000);
            if (!driver.getCurrentUrl().contains(redirectURI) && !driver.getCurrentUrl().contains("s2")) {
                throw new Exception("validate goes to redirect uri.");
            }
        }
    }
}